package com.qf.springmvc.controller;

import com.qf.springmvc.pojo.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author 王博康
 * @version 1.0
 * @project 06_springmvc_interceptor
 * @description: TODO
 * @date 2022/3/8 22:55 星期二
 */
@RestController //代表返回内容为正文,Controller类上加了@RestController注解，等价于在类中的每个方法上都加了@ResponseBody
public class MyController {

    @RequestMapping("/test1") //访问路径,等价于url-pattern
    public String test1(@RequestBody User user){//@RequestBody将请求体中的json数据转换为java对象。
        System.out.println("接收到的信息是："+user.toString());
        return "success";
    }

    @RequestMapping("/test2")
    public User test2(){
        User user = new User();
        user.setName("zhaowentao");
        user.setPassword("123456");
        user.setAge(18);
        user.setAddress("北京");
        user.setBirthday(new Date());
        return user;
    }
}
